library(tourr)
library(plotly)
library(igraph)
library(visNetwork)
library(seriation)
nodes <- read.delim("trainMeta.dat",sep = " ",header = FALSE)
colnames(nodes) <- c("label","group")
nodes$title <- nodes$label
nodes$id <- 1:dim(nodes)[1]
nodes2 <- nodes[,c(4,2,1,3)]
edges <- read.delim("trainData.dat", sep = " ")
edges <- edges[,c(2,3,4)]
colnames(edges) <- c("from","to","value")
graph <- graph_from_data_frame(d=edges, vertices=nodes2, directed=T)
nodes2$value <- strength(graph)
Network <- visNetwork(nodes2, edges)%>%
visPhysics(solver='repulsion') %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = 1,
labelOnly = FALSE, hover = TRUE),
nodesIdSelection = TRUE)
Network
It can be seen that most of the terrorists involved in the bombing are connected to each other directly. Blue ones are those involved in blasting and the other yellow one. There are a few people though who are not directly connected to any of the terrorists involved in bombing. It is seen that the two terrorists with most number of connections, Jamal Zougam, Mohamed Chaoui and Imad Eddin Barakat have not used their close allies for bombings.We can see a number of clusters which appears around Jamal Zougam, Mohamed Chaoui, Said Berrak, Mohamed Chedadi, Basel Ghayoun and it is evident that each cluster is connected to atleast one of the top 3 terrorists with highest number of connections these people also have very strong connection with each other.
We can see three clusters one with two big nodes (Jamal Zougam, Mohamed Chaoui) which are the ones with more connections and who are involved in placing the explosives. Second one with nodes to the right with many connections (Imad Eddin Barakat, Amer Aziz). Third cluster with internal connection which are quite disconnected from all other clusters (Semaan Gaby Eid and other Jose)
Network2 <- visNetwork(nodes, edges)%>%
visPhysics(solver='repulsion') %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = list(from = 1, to = 0),
labelOnly = FALSE, hover = TRUE),
nodesIdSelection = TRUE)
Network2
It seems like Jamal Zougam and Abdeluahid Berrak both had equal and best opportunity to spread the information in the network. Jamal Zougam was believed to be the person who sold telephones which were used to detonate the bombs in the attack. This may be somehow one of the reasons why he was the center of the network. He also reportedly helped construct the bombs and was one of the first to be arrested.
new_nodes1 <- nodes2
graph2 <- graph_from_data_frame(d=edges, vertices=nodes2, directed=F)
ceb <- cluster_edge_betweenness(graph2)
new_nodes1$group=ceb$membership
Network3 <- visNetwork(new_nodes1,edges) %>%
visPhysics(solver='repulsion') %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = 1,labelOnly = FALSE, hover = TRUE))
Network3
A few of the clusters that were identified manually in step 1 were discovered by this clustering method in addition to a few more clusters. One main blue cluster with Mohamed Chaoui, Imad Eddin Barakat and Jamal Zougam which was also identifed in the previous step. Along with it a cluster yellow colored with Semaan Gaby and others can also be recognized. Red colored cluster of connections of Jamal Ahmidan is also visible. More clusters are visible as compared to clusters visible in part 1.
netm <- get.adjacency(graph2, attr="value", sparse=FALSE)
colnames(netm) <- V(graph2)$label
rownames(netm) <- V(graph2)$label
rowdist<-dist(netm)
order1<-seriate(rowdist, "HC")
ord1<-get_order(order1)
reordmatr<-netm[ord1,ord1]
plot_ly(z=~reordmatr, x=~colnames(reordmatr),
y=~rownames(reordmatr), type="heatmap")
The most pronounced cluster seems to appear at the top right corner. These clusters seems to appear mostly around the top terrorists i.e. who had the most number of connections and these clusters were also discovered in the 1st and 3rd plot.
Oilcoal <- read.csv2("Oilcoal.csv")
Oilcoal <- as.data.frame(Oilcoal)
Oilcoal$Coal <- as.numeric(Oilcoal$Coal)
Oilcoal$Oil <- as.numeric(Oilcoal$Oil)
Oilcoal$Marker.size <- as.numeric(Oilcoal$Marker.size)
plot_ly(Oilcoal, x=~Coal, y=~Oil, frame =~Year, size =~Marker.size, color =~Country) %>%
animation_opts(100, easing = "elastic", redraw = F)
By analyzing the animation we can see that all countries seem to have increased its coal and oil consumption. US is being the biggest consumer of Oil all along. China has increased the cunsumption of coal drastically and more than any other country, while the rate of increse of its oil consumption is not as big as that of coal. India seems to be the only other country which increased its Oil and Coal consumtion at a reasonable rate to each other. All the other country’s Coal and Oil consumption seem to remain close to as it was in the beginning and has minimal increase.
df <- Oilcoal[Oilcoal$Country %in% c("India","China"),]
plot_ly(df, x=~Coal, y=~Oil, frame =~Year, size =~Marker.size, color =~Country) %>%
animation_opts(100, easing = "elastic", redraw = F)
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
India and China have similar motion pattern both of the countries are increasing the oil and coal consumption whereas China’s increase is much more then that of India. Both the countries due to increase in polulation are in need of more energy resources. High economic growth in China and India being a developing country increased its oil consumption. China’s and India’s energy use is projected to double from 2005 onwards as both of them need resources to meet there energy demand.
Oilcoal$Oil_p <- Oilcoal$Oil/(Oilcoal$Oil + Oilcoal$Coal)*100
Oilcoal_new <- Oilcoal[rep(row.names(Oilcoal),2), ]
Oilcoal_new[361:720,]$Oil_p <- 0
Oilcoal_new <- Oilcoal_new[,c(1,2,3,4,5,7)]
Oilcoal_new <- Oilcoal_new[order(Oilcoal_new$Year, Oilcoal_new$Country),]
p3 <- Oilcoal_new %>%
plot_ly(x = ~Country, y = ~Oil_p, size = ~Marker.size, color = ~Country,
frame = ~Year, line = list(width = 30), text = ~Country, type = 'scatter',mode = "lines",showlegend = T
)
p3
Using animated Bar chart we can easily recognize the increase in the consumption of the resources by country over time and see which country have more increase in consumption as compared to the others. Whereas bubble chart provides more exact information about the countries and their resource consumption, also it shows both the variables oil and coal. In Bar chart the drawback is that we can only see increase for one variable which is the relation between oil and coal.
p4 <- p3%>%animation_opts(
easing = "elastic", redraw = F)
p4
By adding the easing to the bar chat we can see that the plot is same but the transition is stepwise. We can compare it with easeInOutBounce as it is also in step wise. By using easing we get advantage of change in the countries at the specific year big changes are easily visible. The disadvantage is that we can not see the time transition by using easing it is a sudden change which is not good for analyzing the transition between years.
tour
Clusters does correspond on year ranges to some extent here. Brazil seems to have largest contribution on this projection.
For other Countries Coal consumption do not have a real pattern during years, Brazil Coal consumption increase drastically from 1960 to 1985 and after it from 1980 to 2010 it is an irregular increase as it’s showed in the time series plot below, way more than any other country in the group and hence had the largest contribution to the projection.
Oilcoal %>% filter(Country=="Brazil")%>%ggplot(aes(y=Coal,x=Year))+geom_line()